<?php

define('BASEDIR', __DIR__);

include BASEDIR . '/IMooc/Loader.php';

spl_autoload_register('\\IMooc\\Loader::autoload');

/*
// 策略模式
class Page
{
    protected $strategy;
    function index()
    {
        echo 'AD:';
        $this->strategy->showAd();

        echo 'Category:';
        $this->strategy->showCategory();
    }

    function setStrategy(\IMooc\UserStrategy $strategy)
    {
        $this->strategy = $strategy;
    }
}

$page = new Page;
if (isset($_GET['female'])) {
    $strategy = new \IMooc\FemaleUserStrategy();
} else {
    $strategy = new \IMooc\MaleUserStrategy();
}
$page->setStrategy($strategy);
$page->index();


$user = new \IMooc\User(1);
$user->mobile = '13500000000';
$user->name = 'zhangsan';
$user->regtime = date('Y-m-d H:i:s');
*/

/*
// 对象映射关系模式
class Page 
{
    function index()
    {
        $user = \IMooc\Factory::getUser(1);
        $user->name = 'rango';
        
        $this->test();
        echo 'OK';
    }

    function test()
    {
        $user = \IMooc\Factory::getUser(1);
        $user->mobile = '13500000000';
    }
}
$page = new Page();
$page->index();
*/

/*
// 观察者
class Event extends \IMooc\EventGenerator
{
    function trigger()
    {
        echo "Event <br/> \n";
        $this->notify();
    }
}

class Observer1 implements \IMooc\Observer
{
    function update($event_info = null) 
    {
        echo "逻辑1 <br />\n";
    }
}

class Observer2 implements \IMooc\Observer
{
    function update($event_info = null) 
    {
        echo "逻辑2 <br />\n";
    }
}

$event = new Event();
$event->addObserver(new Observer1);
$event->addObserver(new Observer2);
$event->trigger();
*/

/*
// 原型模式
$prototype = new IMooc\Canvas();
$prototype->init();
//------------------------
$canvas1 = clone $prototype;
$canvas1->rect(3, 6, 4, 12);
$canvas1->draw();
echo "==================================<br />";
$canvas2 = clone $prototype;
$canvas2->rect(1, 3, 2, 6);
$canvas2->draw();
*/

/*
// 装饰器模式
$canvas1 = new IMooc\Canvas();
$canvas1->init();
$canvas1->addDecorator(new IMooc\ColorDecorator('green'));
$canvas1->addDecorator(new IMooc\SizeDecorator('10px'));
$canvas1->rect(3, 6, 4, 12);
$canvas1->draw();
*/

/*
// 迭代器模式
$users = new IMooc\AllUser();
foreach ($users as $user)
{
    var_dump($user->name);
    $user->serial_no = rand(10000, 90000);
}
*/

/*
// 代理模式
$proxy = new IMooc\Proxy();
$proxy->getUserName($id);
$proxy->setUserName($id, $proxy);
*/

// 自动加载配置
$config = new IMooc\Config(__DIR__ . '/configs');
var_dump($config['controller']);
